package com.surekam.dma.web.dma;

import java.util.List;

import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;
import org.springside.modules.utils.web.struts2.Struts2Utils;

import com.surekam.dma.entity.dma.Subject;
import com.surekam.dma.service.dma.SubjectManager;
import com.surekam.dma.web.CrudActionSupport;

//定义URL映射对应/demo/subject.action
@Namespace("/demo")
public class SubjectAction extends CrudActionSupport<Subject> {
	private static final long serialVersionUID = 1433661063653771152L;

	private Long id;
	private Subject entity;
	private Page<Subject> page = new Page<Subject>();//每页8条记录
	private SubjectManager subjectManager;
	
	public String helloWorld() throws Exception{
		System.out.println("你好，Action！");
		return SUCCESS;
	}
	
	public void setId(Long id) {
		this.id = id;
	}

	public Subject getModel() {
		return entity;
	}

	
	protected void prepareModel() throws Exception {
		if (id != null) {
			entity = subjectManager.getSubject(id);
		} else {
			entity = new Subject();
		}
	}

	

	
	public String input() throws Exception {
		
		return INPUT;
	}

	
	public String save() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	
	public String delete() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	
	
	public void setSubjectManager(SubjectManager subjectManager) {
		this.subjectManager = subjectManager;
	}

	public Page<Subject> getPage() {
		return page;
	}

	@Override
	
	public String list() throws Exception {
		List<PropertyFilter> filters = PropertyFilter.buildFromHttpRequest(Struts2Utils.getRequest());
		//设置默认排序方式
		if (!page.isOrderBySetted()) {
			page.setOrderBy("date");
			page.setOrder(Page.ASC);
		}
		page = subjectManager.searchSubject(page, filters);
		return SUCCESS;
	}
}
